Skip to content

Conversation

@tzolov
Copy link
Contributor

@tzolov tzolov commented Nov 19, 2024

  • Modify stream method to support recursive tool call handling
  • Update token tracking and metadata merging for streamed responses
  • Improve token usage calculation for tool use events
  • Update test cases to handle new response processing

Resolves #1743

@tzolov tzolov added this to the 1.0.0-M4 milestone Nov 19, 2024
@tzolov tzolov added the bug Something isn't working label Nov 19, 2024

DefaultUsage usage = new DefaultUsage(promptTokens, generationTokens, totalTokens);

Document modelResponseFields = response.additionalModelResponseFields();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't seem to use modelResponseFields and metrics. Also, we don't copy all the metadata attributes into the ChatResponse here.

&& this.isToolCall(chatResponse, Set.of("tool_use"))) {
var toolCallConversation = this.handleToolCalls(prompt, chatResponse);
return this.call(new Prompt(toolCallConversation, prompt.getOptions()));
return this.internalCall(new Prompt(toolCallConversation, prompt.getOptions()), chatResponse);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need test coverage to test this flow - especially to verify the final ChatResponse containing the preceding one.

if (perviousChatResponse != null && perviousChatResponse.getMetadata() != null
&& perviousChatResponse.getMetadata().getUsage() != null) {

promptTokens += perviousChatResponse.getMetadata().getUsage().getPromptTokens();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have manually verified this step. Is there an effective way we can add a test to validate this additive operation in our tests?

- Modify stream method to support recursive tool call handling
- Update token tracking and metadata merging for streamed responses
- Improve token usage calculation for tool use events
- Update test cases to handle new response processing

Resolves spring-projects#1743
- Modify call method to support recursive tool call handling
- Add support for cumulative token tracking across tool call iterations
- Introduce internal call method to track and aggregate token usage
- Merge previous chat response tokens with current response tokens
@tzolov tzolov force-pushed the fix-bedrock-converse-tool-usage branch from 65936a9 to 625a557 Compare November 20, 2024 08:12
@ilayaperumalg
Copy link
Member

Thanks for updating the tests! LGTM, merging.

@ilayaperumalg
Copy link
Member

Rebased, squashed, fixed check style error and merged as 00ede3f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using BedrockProxyChatModel with tools, chatResponse.metadata.usage is returning ONLY the last model invocation usage

2 participants